package top

import (
	"github.com/gin-gonic/gin"
	"go-interview-forum/resp"
	"go-interview-forum/service/top"
)

type Info struct {
	Id int `json:"id"`
}

// OverallRanking 总榜
func OverallRanking(g *gin.Context) {
	tops, err := top.OverallRanking()
	if err != nil {
		resp.QueryErrorResp(g, err.Error())
		return
	}
	resp.SuccessResp(g, tops)
}

// GraspRanking 掌握榜
func GraspRanking(g *gin.Context) {
	tops, err := top.GraspRanking()
	if err != nil {
		resp.QueryErrorResp(g, err.Error())
		return
	}
	resp.SuccessResp(g, tops)
}

// LengthTimeRanking 时长榜
func LengthTimeRanking(g *gin.Context) {
	ranking, err := top.LengthTimeRanking()
	if err != nil {
		resp.QueryErrorResp(g, err.Error())
		return
	}
	resp.SuccessResp(g, ranking)
}

// CategorizationRanking 分类榜
func CategorizationRanking(g *gin.Context) {
	var info Info
	err := g.ShouldBind(&info)
	if err != nil {
		return
	}
	ranking, err := top.CategorizationRanking(info.Id)
	if err != nil {
		resp.QueryErrorResp(g, err.Error())
		return
	}
	resp.SuccessResp(g, ranking)
}
